﻿using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using Xoohoo.Extensions;
using Xoohoo.Models.InputModels;
using Xoohoo.Repositories.SqlServerEF.Entities;
using XM = Xoohoo.Models;

namespace Xoohoo.Repositories.SqlServerEF
{
    public class BulletinRepository : RepositoryBase<Bulletin>, IBulletinRepository
    {
        public XM.Bulletin GetItem()
        {
            return DbSet.FirstOrDefault().ToModel<XM.Bulletin>();
        }

        public bool Save(BulletinInput bulletin)
        {
            Bulletin dbBulletin = DbSet.FirstOrDefault();
            if (dbBulletin == null) return false;

            dbBulletin.UpdateFrom(bulletin);
            DB.SaveChanges();

            return true;
        }

    }
}
